/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package telas;

import Funcoes.Funcao;
import classes.Cliente;
import classes.Equipamento;
import classes.Venda;
import javax.persistence.EntityManager;
import javax.persistence.Query;

/**
 *
 * @author Iserj
 */
public class relatorio extends javax.swing.JInternalFrame {

    EntityManager gerenciador;
    Query consulta;
    Cliente cliente = new Cliente();
    Equipamento equipamento = new Equipamento();
    Venda venda = new Venda();

    /**
     * Creates new form relatorio
     */
    public relatorio() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txt_busca_pedido = new javax.swing.JTextField();
        btn_buscar_rel = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        lbl_nome = new javax.swing.JLabel();
        lbl_equip = new javax.swing.JLabel();
        cpf = new javax.swing.JLabel();
        lbl_codigo = new javax.swing.JLabel();
        valor_lbl = new javax.swing.JLabel();
        lbl_data = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jrb_cartao_credito = new javax.swing.JRadioButton();
        jrb_cartao_debito = new javax.swing.JRadioButton();
        jrb_avista = new javax.swing.JRadioButton();

        setClosable(true);
        setTitle("Controle de Venda");

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setText("Número do pedido:");

        btn_buscar_rel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/botao_procurar.png"))); // NOI18N
        btn_buscar_rel.setText("Exibir relatório");
        btn_buscar_rel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_buscar_relActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addComponent(jLabel1)
                .addGap(26, 26, 26)
                .addComponent(txt_busca_pedido, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(28, 28, 28)
                .addComponent(btn_buscar_rel)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(17, 17, 17)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txt_busca_pedido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btn_buscar_rel))
                .addContainerGap(25, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        lbl_nome.setText("Nome:");

        lbl_equip.setText("Equipamento:");

        cpf.setText("CPF:");

        lbl_codigo.setText("Código:");

        valor_lbl.setText("Valor:");

        lbl_data.setText("Data:");

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel7.setText("Forma de pagamento:");

        jrb_cartao_credito.setText("Cartão de crédito");
        jrb_cartao_credito.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrb_cartao_creditoActionPerformed(evt);
            }
        });

        jrb_cartao_debito.setText("Carrtão de débito");
        jrb_cartao_debito.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrb_cartao_debitoActionPerformed(evt);
            }
        });

        jrb_avista.setText("À vista");
        jrb_avista.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrb_avistaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(41, 41, 41)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbl_equip)
                            .addComponent(valor_lbl)
                            .addComponent(lbl_nome, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(203, 203, 203)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cpf)
                            .addComponent(lbl_codigo)
                            .addComponent(lbl_data)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jrb_cartao_debito)
                        .addGap(72, 72, 72)
                        .addComponent(jrb_cartao_credito)))
                .addGap(35, 35, 35)
                .addComponent(jrb_avista)
                .addContainerGap(46, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel7)
                .addGap(193, 193, 193))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_nome)
                    .addComponent(cpf))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl_codigo)
                    .addComponent(lbl_equip))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addComponent(valor_lbl)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE)
                        .addComponent(jLabel7)
                        .addGap(18, 18, 18))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(lbl_data)
                        .addGap(73, 73, 73)))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jrb_cartao_debito)
                    .addComponent(jrb_cartao_credito, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jrb_avista))
                .addGap(38, 38, 38))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(22, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(44, 44, 44)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(42, 42, 42)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btn_buscar_relActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_buscar_relActionPerformed

        gerenciador = Funcao.conectar(); // abre a conexão com o banco

        int cod = Integer.parseInt(this.txt_busca_pedido.getText());
        consulta = gerenciador.createQuery("select c from Venda c where c.idvenda = :id");
        consulta.setParameter("id", cod);
        venda = (Venda) consulta.getSingleResult();
        this.lbl_data.setText(venda.getData());
        this.lbl_nome.setText("Nome: " + venda.getCliente().getCliNome());
        this.cpf.setText("CPF: " + venda.getCliente().getCliCpf());
        this.lbl_equip.setText("Equipamento: " + venda.getEquipamento().getEqui_nome());
        this.lbl_codigo.setText("Codigo: " + venda.getEquipamento().getEqui_cod());
        this.valor_lbl.setText("Valor: " +venda.getEquipamento().getEqui_preco());

        if (jrb_cartao_credito.isSelected()) {
            venda.setTipoCartaoCredito(this.jrb_cartao_credito.isSelected());
        }

        if (jrb_cartao_debito.isSelected()) {
            venda.setTipoCartaoDebito(this.jrb_cartao_debito.isSelected());
        }

        if (jrb_avista.isSelected()) {
            venda.setTipoAVista(this.jrb_avista.isSelected());
        }

        Funcao.fechar(gerenciador); // fecha conexão com o banco 
    }//GEN-LAST:event_btn_buscar_relActionPerformed

    private void jrb_avistaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrb_avistaActionPerformed

        jrb_cartao_credito.setEnabled(false);
        jrb_cartao_debito.setEnabled(false);
        jrb_avista.setEnabled(true);        //desativa todos e ativa c. credito.
        //comandos para ativar segmento da venda
        valor_lbl.setEnabled(true);
    }//GEN-LAST:event_jrb_avistaActionPerformed

    private void jrb_cartao_debitoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrb_cartao_debitoActionPerformed

        jrb_cartao_credito.setEnabled(false);        // desativa todos e ativa c. debito
        jrb_cartao_debito.setEnabled(true);
        jrb_avista.setEnabled(false);
        //comandos para ativar segmento da venda
        valor_lbl.setEnabled(true);
    }//GEN-LAST:event_jrb_cartao_debitoActionPerformed

    private void jrb_cartao_creditoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrb_cartao_creditoActionPerformed

        jrb_cartao_credito.setEnabled(true); // desativa todos e ativa c. credito
        jrb_cartao_debito.setEnabled(false);
        jrb_avista.setEnabled(false);
        //comandos para ativar segmento da venda

        valor_lbl.setEnabled(true);
    }//GEN-LAST:event_jrb_cartao_creditoActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_buscar_rel;
    private javax.swing.JLabel cpf;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JRadioButton jrb_avista;
    private javax.swing.JRadioButton jrb_cartao_credito;
    private javax.swing.JRadioButton jrb_cartao_debito;
    private javax.swing.JLabel lbl_codigo;
    private javax.swing.JLabel lbl_data;
    private javax.swing.JLabel lbl_equip;
    private javax.swing.JLabel lbl_nome;
    private javax.swing.JTextField txt_busca_pedido;
    private javax.swing.JLabel valor_lbl;
    // End of variables declaration//GEN-END:variables
}
